<template>
  <div class="purchase_view">
    <el-dialog :title="title" center :visible.sync="open" width="750px" append-to-body>
      <el-tabs v-model="activeName">
        <el-tab-pane label="流程表单" name="first"></el-tab-pane>
        <el-tab-pane label="流程导入" name="second" v-if="form.instanceId">
            <FlowChoose ref="workFlow" @workflow="setWorkflow" :businessType="form.businessTypeOpt"></FlowChoose>
        </el-tab-pane>
      </el-tabs>

      <el-form ref="form" :model="form" :rules="rules" label-width="100px" v-if="activeName=='first'">
        <el-form-item style="margin-top: 0" label="流程创建" prop="createUserId">
          <span style="color: #0000ee">{{form.createTime}} {{form.createBy}}创建</span>
          <div style="float:right;">
              <el-button
              :class="showCopy?'active dis_active':'active'"
              type="text"
              @click="showCopy=showCopy?false:true"
          >新建抄送</el-button>
            </div>
        </el-form-item>
        <el-form-item label="任务抄送" prop="checkedUserList" v-if="showCopy">
          <div class="purchase_s_view">
            <el-select :value="selectCopyToUsers" @clear="clearSelect('copyToUsers')"
							size="small" multiple placeholder="请选择任务抄送" clearable style="width: 100%"></el-select>
            <ChooseUser @chooseUsers ="setCopyToUsers" ></ChooseUser>
          </div>
        </el-form-item>
        <el-form-item label="流程名称" prop="flowName">
          <el-input
          placeholder="请输入流程名称"
          clearable
          v-model="form.flowName"
          size="small"
        />
        </el-form-item>
        <el-row>
          <el-col :span="12">
            <el-form-item label="调课类型" prop="type">
              <el-select
                v-model="form.type"
                size="small"
                style="width: 100%"
                @change="changeType">
                <el-option v-for="item in adjustTypeList" :key="item.label" :label="item.label"
                  :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <div style="float:right;">
              <el-button type="text" @click="resetCourse">重置</el-button>
              <el-button type="text" @click="selectCourse1">调课课程</el-button>
              <el-button type="text" v-if="form.type == 2" @click="selectCourse2">目标课程</el-button>
            </div>
          </el-col>
        </el-row>
        <el-form-item label="课程信息:" style="margin-bottom: 0" v-if="form.course1.courseId">
        </el-form-item>
        <el-form-item label-width="0" v-if="form.course1.courseId">
          <el-row>
            <el-col :span="12">
              <el-form-item label="学院" prop="collegeOrgId" class="item">
                {{course1ColleageName}}
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="实验室" prop="course1.labId"
                :rules="{
                  required: true, message: '实验室不能为空', trigger: 'blur'
                }">
                <el-select
                  :disabled="form.type == 2"
                  size="small"
                  class="input_w"
                  v-model="form.course1.labId"
                  placeholder="请选择实验室">
                  <el-option v-for="item in lab1List" :key="item.orgName" :label="item.orgName"
                    :value="item.orgId">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="开课地点" prop="course1.classRoomId"
                :rules="{
                  required: true, message: '开课地点不能为空', trigger: 'blur'
                }">
                <el-input :disabled="form.type == 2" size="small" class="input_w" v-model="form.course1.classRoomId" placeholder="请输入开课地点" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="专业" class="item">
                {{course1MajorOpt}}
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="课程编码" class="item">
                {{form.course1.courseNo}}
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="课程名称" class="item">
                {{form.course1.courseName}}
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="实验项目" class="item">
                {{form.course1.experimentalProject}}

              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="实验学时" class="item">
                {{form.course1.experimentalHours}}
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="班级" class="item">
                {{form.course1.classNo}}
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="人数" class="item">
                {{form.course1.personNum}}
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="每组人数" prop="personsOfGroup">
                <el-input type="number" min="1" v-model="form.course1.personsOfGroup" placeholder="每组人数"/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="周次">
                <el-input type="number" min="1" v-model="form.course1.weekOpenNums" placeholder="周次"  :disabled="form.type == 2"/>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="周一">
                <el-row>
                  <el-col :span="12">
                    <el-form-item prop="day1" style="width: 122px;">
                      <el-input type="number" min="1" v-model="form.course1.day11" placeholder="节次开始"  :disabled="form.type == 2"/>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item prop="day1" style="width: 122px;">
                      <el-input type="number" min="1" v-model="form.course1.day12" placeholder="节次结束"  :disabled="form.type == 2"/>
                    </el-form-item>
                  </el-col>
                </el-row>
              </el-form-item>
            </el-col>
            <el-col :span="12">
                <el-form-item label="周二">
                  <el-row>
                    <el-col :span="12">
                      <el-form-item prop="day2" style="width: 122px;">
                        <el-input type="number" min="1" v-model="form.course1.day21" placeholder="节次开始"  :disabled="form.type == 2"/>
                      </el-form-item>
                    </el-col>
                    <el-col :span="12">
                      <el-form-item prop="day2" style="width: 122px;">
                        <el-input type="number" min="1" v-model="form.course1.day22" placeholder="节次结束"  :disabled="form.type == 2"/>
                      </el-form-item>
                    </el-col>
                  </el-row>
                </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="周三">
                <el-row>
                  <el-col :span="12">
                    <el-form-item prop="day3" style="width: 122px;">
                      <el-input type="number" min="1" v-model="form.course1.day31" placeholder="节次开始"  :disabled="form.type == 2"/>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item prop="day3" style="width: 122px;">
                      <el-input type="number" min="1" v-model="form.course1.day32" placeholder="节次结束"  :disabled="form.type == 2"/>
                    </el-form-item>
                  </el-col>
                </el-row>
              </el-form-item>
            </el-col>
            <el-col :span="12">
                <el-form-item label="周四">
                  <el-row>
                    <el-col :span="12">
                      <el-form-item prop="day4" style="width: 122px;">
                        <el-input type="number" min="1" v-model="form.course1.day41" placeholder="节次开始"  :disabled="form.type == 2"/>
                      </el-form-item>
                    </el-col>
                    <el-col :span="12">
                      <el-form-item prop="day4" style="width: 122px;">
                        <el-input type="number" min="1" v-model="form.course1.day42" placeholder="节次结束"  :disabled="form.type == 2"/>
                      </el-form-item>
                    </el-col>
                  </el-row>
                </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="周五">
                <el-row>
                  <el-col :span="12">
                    <el-form-item prop="day5" style="width: 122px;">
                      <el-input type="number" min="1" v-model="form.course1.day51" placeholder="节次开始"  :disabled="form.type == 2"/>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item prop="day5" style="width: 122px;">
                      <el-input type="number" min="1" v-model="form.course1.day52" placeholder="节次结束"  :disabled="form.type == 2"/>
                    </el-form-item>
                  </el-col>
                </el-row>
              </el-form-item>
            </el-col>
            <el-col :span="12">
                <el-form-item label="周六">
                  <el-row>
                    <el-col :span="12">
                      <el-form-item prop="day6" style="width: 122px;">
                        <el-input type="number" min="1" v-model="form.course1.day61" placeholder="节次开始"  :disabled="form.type == 2"/>
                      </el-form-item>
                    </el-col>
                    <el-col :span="12">
                      <el-form-item prop="day6" style="width: 122px;">
                        <el-input type="number" min="1" v-model="form.course1.day62" placeholder="节次结束"  :disabled="form.type == 2"/>
                      </el-form-item>
                    </el-col>
                  </el-row>
                </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="周日">
                <el-row>
                  <el-col :span="12">
                    <el-form-item prop="day7" style="width: 122px;">
                      <el-input type="number" min="1" v-model="form.course1.day71" placeholder="节次开始"  :disabled="form.type == 2"/>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item prop="day7" style="width: 122px;">
                      <el-input type="number" min="1" v-model="form.course1.day72" placeholder="节次结束"  :disabled="form.type == 2"/>
                    </el-form-item>
                  </el-col>
                </el-row>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row v-for="(teacher, index) in form.course1.courseTeacherList" :key="index">
            <el-col :span="12">
              <el-form-item label="老师工号">
                <el-input size="small" v-model="teacher.teacherNo" disabled placeholder="请输老师工号" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="老师姓名">
                <el-input size="small" v-model="teacher.teacherName" disabled placeholder="请输老师姓名" />
              </el-form-item>
            </el-col>
          </el-row>
        </el-form-item>

        <el-form-item label="目标课程:" style="margin-bottom: 0" v-if="form.type == 2 && form.course2.courseId">
        </el-form-item>
        <el-form-item label-width="0" v-if="form.type == 2 && form.course2.courseId">
          <el-row>
            <el-col :span="12">
              <el-form-item label="学院" class="item">
                {{course2ColleageName}}
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="实验室" prop="course2.labId">
                <el-select
                  :disabled="form.type == 2"
                  size="small"
                  class="input_w"
                  v-model="form.course2.labId"
                  placeholder="请选择实验室">
                  <el-option v-for="item in lab1List" :key="item.orgName" :label="item.orgName"
                    :value="item.orgId">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="开课地点" prop="course2.classRoomId">
                <el-input :disabled="form.type == 2" size="small" class="input_w" v-model="form.course2.classRoomId" placeholder="请输入开课地点" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="专业" class="item">
                {{course2MajorOpt}}
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="课程编码" class="item">
                {{form.course2.courseNo}}
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="课程名称" class="item">
                {{form.course2.courseName}}
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="实验项目" class="item">
                {{form.course2.experimentalProject}}

              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="实验学时" class="item">
                {{form.course2.experimentalHours}}
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="班级" class="item">
                {{form.course2.classNo}}
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="人数" class="item">
                {{form.course2.personNum}}
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="每组人数" prop="personsOfGroup">
                <el-input type="number" min="1" v-model="form.course2.personsOfGroup" placeholder="每组人数" disabled/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="周次">
                <el-input type="number" min="1" v-model="form.course2.weekOpenNums" placeholder="周次" disabled/>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="周一">
                <el-row>
                  <el-col :span="12">
                    <el-form-item prop="day1" style="width: 122px;">
                      <el-input type="number" min="1" v-model="form.course2.day11" placeholder="节次开始" disabled/>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item prop="day1" style="width: 122px;">
                      <el-input type="number" min="1" v-model="form.course2.day12" placeholder="节次结束" disabled/>
                    </el-form-item>
                  </el-col>
                </el-row>
              </el-form-item>
            </el-col>
            <el-col :span="12">
                <el-form-item label="周二">
                  <el-row>
                    <el-col :span="12">
                      <el-form-item prop="day2" style="width: 122px;">
                        <el-input type="number" min="1" v-model="form.course2.day21" placeholder="节次开始" disabled/>
                      </el-form-item>
                    </el-col>
                    <el-col :span="12">
                      <el-form-item prop="day2" style="width: 122px;">
                        <el-input type="number" min="1" v-model="form.course2.day22" placeholder="节次结束" disabled/>
                      </el-form-item>
                    </el-col>
                  </el-row>
                </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="周三">
                <el-row>
                  <el-col :span="12">
                    <el-form-item prop="day3" style="width: 122px;">
                      <el-input type="number" min="1" v-model="form.course2.day31" placeholder="节次开始" disabled/>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item prop="day3" style="width: 122px;">
                      <el-input type="number" min="1" v-model="form.course2.day32" placeholder="节次结束" disabled/>
                    </el-form-item>
                  </el-col>
                </el-row>
              </el-form-item>
            </el-col>
            <el-col :span="12">
                <el-form-item label="周四">
                  <el-row>
                    <el-col :span="12">
                      <el-form-item prop="day4" style="width: 122px;">
                        <el-input type="number" min="1" v-model="form.course2.day41" placeholder="节次开始" disabled/>
                      </el-form-item>
                    </el-col>
                    <el-col :span="12">
                      <el-form-item prop="day4" style="width: 122px;">
                        <el-input type="number" min="1" v-model="form.course2.day42" placeholder="节次结束" disabled/>
                      </el-form-item>
                    </el-col>
                  </el-row>
                </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="周五">
                <el-row>
                  <el-col :span="12">
                    <el-form-item prop="day5" style="width: 122px;">
                      <el-input type="number" min="1" v-model="form.course2.day51" placeholder="节次开始" disabled/>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item prop="day5" style="width: 122px;">
                      <el-input type="number" min="1" v-model="form.course2.day52" placeholder="节次结束" disabled/>
                    </el-form-item>
                  </el-col>
                </el-row>
              </el-form-item>
            </el-col>
            <el-col :span="12">
                <el-form-item label="周六">
                  <el-row>
                    <el-col :span="12">
                      <el-form-item prop="day6" style="width: 122px;">
                        <el-input type="number" min="1" v-model="form.course2.day61" placeholder="节次开始" disabled/>
                      </el-form-item>
                    </el-col>
                    <el-col :span="12">
                      <el-form-item prop="day6" style="width: 122px;">
                        <el-input type="number" min="1" v-model="form.course2.day62" placeholder="节次结束" disabled/>
                      </el-form-item>
                    </el-col>
                  </el-row>
                </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="周日">
                <el-row>
                  <el-col :span="12">
                    <el-form-item prop="day7" style="width: 122px;">
                      <el-input type="number" min="1" v-model="form.course2.day71" placeholder="节次开始" disabled/>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item prop="day7" style="width: 122px;">
                      <el-input type="number" min="1" v-model="form.course2.day72" placeholder="节次结束" disabled/>
                    </el-form-item>
                  </el-col>
                </el-row>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row v-for="(teacher, index) in form.course2.courseTeacherList" :key="index">
            <el-col :span="12">
              <el-form-item label="老师工号">
                <el-input size="small" v-model="teacher.teacherNo" disabled placeholder="请输老师工号" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="老师姓名">
                <el-input size="small" v-model="teacher.teacherName" disabled placeholder="请输老师姓名" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :offset="16" style="margin-top: 10px">
              <el-button type="primary" size="small" @click="changeCourseTime">执行交换</el-button>
            </el-col>
          </el-row>
        </el-form-item>
      </el-form>

      <SelectCourseDate @setCourse1="setCourse1" @setCourse2="setCourse2" ref="selectCourseDate"></SelectCourseDate>

      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm" v-if="activeName=='first'">保存</el-button>
        <el-button type="primary" @click="submitWorkflow" v-if="activeName=='second'">提交</el-button>
        <el-button @click="cancel">关 闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import ChooseUser from "@/views/labsafety/safetyCompents/check_user.vue"
import { getCheckedList } from "@/api/labdata/employee"
import FlowChoose from '@/views/labdata/flowDefination/flow_choose.vue'
import { formatCurrentDate } from "@/utils/index"
import { getOrgByFunctionOpt, listSecondOrgLab } from "@/api/labdata/orgnization"
import { getCourse } from "@/api/course/course"
import { getAdjust, addAdjust, updateAdjust, submitAdjust } from "@/api/course/adjust"
import SelectCourseDate from '@/views/course/course/select_course_date.vue'

export default {
  components: {
    FlowChoose, ChooseUser, SelectCourseDate
  },
  name: "CreateDialog",
  data() {
    return {
      adjustTypeList: [
        {
          label: '现有课程调整',
          value: 1
        },
        {
          label: '交换课程调整',
          value: 2
        }
      ],
      copyToUsers: [],
      activeName: 'first',
      // 遮罩层
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      showCopy: false,
      //二级机构
      collegeList: [],
      //二级机构下的实验室
      lab1List: [],
      lab2List: [],
      weekDayOptOptions: [],
      majorOptOptions: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 100,
        instanceId: null,
      },
      // 表单参数
      form: {
        type: 1,
        course1: {},
        course2: {}
      },
      // 表单校验
      rules: {
        flowName: { required: true, message: "流程名称不能为空", trigger: "blur" },
        type: { required: true, message: "调课类型不能为空", trigger: "blur" }
      }
    };
  },
  created() {
    // 学院
    this.getCollegeList()
    // 星期
    this.getDicts("weekDayOpt").then(response => {
        this.weekDayOptOptions = response.data;
    });
    this.getDicts("majorOpt").then(response => {
        this.majorOptOptions = response.data;
    })
  },
  computed: {
    selectCopyToUsers() {
      return this.copyToUsers.map(item => item.nickName)
    },
    course1MajorOpt() {
      if (this.form.course1.majorOpt) {
        const dict = this.majorOptOptions.find(item => item.dictValue == this.form.course1.majorOpt)
        return dict.dictLabel
      }
      return ''
    },
    course2MajorOpt() {
      if (this.form.course2.majorOpt) {
        const dict = this.majorOptOptions.find(item => item.dictValue == this.form.course2.majorOpt)
        return dict.dictLabel
      }
      return ''
    },
    course1ColleageName() {
      if (this.form.course1.collegeOrgId) {
        const college = this.collegeList.find(item => item.orgId == this.form.course1.collegeOrgId)
        return college.orgName
      }
      return ''
    },
    course2ColleageName() {
      if (this.form.course2.collegeOrgId) {
        const college = this.collegeList.find(item => item.orgId == this.form.course2.collegeOrgId)
        return college.orgName
      }
      return ''
    }
  },
  methods: {
    getCollegeList(){
      getOrgByFunctionOpt(2).then(response => {
        this.collegeList = response.data
      });
    },
    getLabList1(id) {
      listSecondOrgLab(id).then(response => {
        this.lab1List = response.data
      });
    },
    getLabList2(id) {
      listSecondOrgLab(id).then(response => {
        this.lab2List = response.data
      });
    },
    setWorkflow(workflowId){
      this.form.workflowId = workflowId;
    },
    submitWorkflow(){
		if(!this.form.workflowId){
		  this.form.workflowId = this.$refs["workFlow"].getWorkflowId();
		}
        submitAdjust(this.form).then(response => {
          this.msgSuccess("修改成功");
          this.open = false;
          this.$emit("refresh");
        });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        type: 1,
        course1: {},
        course2: {}
      };
      this.copyToUsers = []
      this.lab1List = []
      this.lab2List = []
      this.resetForm("form");
      this.showCopy = false
      this.activeName = 'first';
    },
    /** 新增按钮操作 */
    handleAdd(courseDateId) {
      this.reset();
      this.form.createTime  = formatCurrentDate()
      const currentUsername = this.$store.state.user.name
      this.form.createBy = currentUsername
      this.form.type = 1
      this.open = true;
      this.title = "新建调课表单";
      if (courseDateId) {
        getCourse(courseDateId).then(response => {
          this.form.course1 = response.data;
          this.getLabList1(this.form.course1.collegeOrgId)
          if (this.form.type == 2) {
            this.getLabList2(this.form.course2.collegeOrgId)
          }
        })
      }
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      this.open = true;
      this.title = "修改调课表单";
      const instanceId = row.instanceId
      getAdjust(instanceId).then(response => {
        this.form = response.data;
        for(var i=1;i<=7;i++){
          if(this.form.course1['day'+i]){
            let arr = this.form.course1['day'+i].split("-");
            this.form.course1['day'+i+'1']= arr[0];
            this.form.course1['day'+i+'2'] = arr[1];
          }
          if(this.form.course2['day'+i]){
            let arr = this.form.course2['day'+i].split("-");
            this.form.course2['day'+i+'1']= arr[0];
            this.form.course2['day'+i+'2'] = arr[1];
          }
        }
        this.getLabList1(this.form.course1.collegeOrgId)
        if (this.form.type == 2) {
          this.getLabList2(this.form.course2.collegeOrgId)
        } else {
          this.$set(this.form, 'course2', {})
        }
        if(this.form.copyToUsers){
          getCheckedList({checkedUserIds:this.form.copyToUsers}).then(res=>{
            this.setCopyToUsers(res.data)
            this.showCopy = true
          });
        }
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.type == 1 && !this.form.course1.courseId) {
              this.msgError("调整课程不能为空");
              return
          }
          if (this.form.type == 2 && !this.form.course2.courseId) {
              this.msgError("目标课程不能为空");
              return
          }
          for(var i=1;i<=7;i++){
            if(this.form.course1['day'+i+'1'] && this.form.course1['day'+i+'2'] ){
               this.form.course1['day'+i] = this.form.course1['day'+i+'1'] + '-' + this.form.course1['day'+i+'2'];
            }else{
              this.form.course1['day'+i] =  null;
            }
            if(this.form.course2['day'+i+'1'] && this.form.course2['day'+i+'2'] ){
               this.form.course2['day'+i] = this.form.course2['day'+i+'1'] + '-' + this.form.course2['day'+i+'2'];
            }else{
              this.form.course2['day'+i] = null;
            }
          }
          if (this.form.instanceId != null) {
            updateAdjust(this.form).then(response => {
              this.msgSuccess("修改成功");
              //this.form = response.data;
              this.activeName = "second";
            });
          } else {
            addAdjust(this.form).then(response => {
              this.msgSuccess("新增成功");
              //this.form = response.data;
              this.form.instanceId = response.data.instanceId;
              this.activeName = "second";
            });
          }
          this.$emit("refresh")
        }
      });
    },
    refreshChoose() {
      this.$forceUpdate();
    },
    setCopyToUsers(list) {	// 抄送人员
      this.copyToUsers = list
      this.form.copyToUsers = ''
      list.forEach((item, index) => {
        if (index > 0) {
          this.form.copyToUsers += ','
        }
        this.form.copyToUsers += item.userId
      });
    },
    selectCourse1() {
      this.$refs['selectCourseDate'].handleShow(1)
    },
    selectCourse2() {
      if (!this.form.course1.courseId) {
        this.msgError("请先选择调整课程");
        return
      }
      this.$refs['selectCourseDate'].handleShow(2)
    },
    setCourse1(course) {
      this.form.course2 = {}
      getCourse(course.courseId).then(response => {
        this.form.course1 = response.data
        for(var i=1;i<=7;i++){
          if(this.form.course1['day'+i]){
            let arr = this.form.course1['day'+i].split("-");
            this.form.course1['day'+i+'1']= arr[0];
            this.form.course1['day'+i+'2'] = arr[1];
          }
        }
        this.getLabList1(this.form.course1.collegeOrgId)
      })
    },
    setCourse2(course) {
      if (this.form.course1.courseId == course.courseId) {
        this.msgError("目标课程不能与调整课程相同");
        return
      }
      getCourse(course.courseId).then(response => {
        this.form.course2 = response.data
        for(var i=1;i<=7;i++){
          if(this.form.course2['day'+i]){
            let arr = this.form.course2['day'+i].split("-");
            this.form.course2['day'+i+'1']= arr[0];
            this.form.course2['day'+i+'2'] = arr[1];
          }
        }
        this.getLabList2(this.form.course2.collegeOrgId)
      })
    },
    changeType() {
      this.form.course1 = {}
      this.form.course2 = {}
    },
    changeCourseAddr () {
      const labId1 = this.form.course1.labId
      const labId2 = this.form.course2.labId
      this.form.course1.labId = labId2
      this.form.course2.labId = labId1

      const classRoomId1 = this.form.course1.classRoomId
      const classRoomId2 = this.form.course2.classRoomId
      this.form.course1.classRoomId = classRoomId2
      this.form.course2.classRoomId = classRoomId1
    },
    changeCourseTime() {
      if(this.form.course1.weekOpenNums!=this.form.course2.weekOpenNums ){
        this.msgError("请输入目标课程与调整课程的周次必须相同");
        return
      }
      this.changeCourseAddr();
      for(var i=1;i<=7;i++){
        const course1dayStart = this.form.course1['day'+i+'1'];
        const course1dayEnd = this.form.course1['day'+i+'2'];
        const course2dayStart = this.form.course2['day'+i+'1'];
        const course2dayEnd = this.form.course2['day'+i+'2'];
        this.form.course1['day'+i+'1'] = course2dayStart;
        this.form.course1['day'+i+'2'] = course2dayEnd;
        this.form.course2['day'+i+'1'] = course1dayStart;
        this.form.course2['day'+i+'2'] = course1dayEnd;
      }
    },
    resetCourse() {
      this.form.course1 = {}
      this.form.course2 = {}
    }
  }
};
</script>

<style scoped>
  .el-button.active{
    text-decoration: underline;
    color: #0000ee;
  }
  .el-button.dis_active {
    color: #999999
  }
  .purchase_s_view {
    display: flex;
    flex-direction: row;
    align-items: left;
    justify-content: left;
  }
  .input_w{
    width: 100%;
  }
  /deep/ .el-form-item {
    margin-bottom: 14px;
  }
  .item{
    margin-bottom: 0px;
  }
</style>
